import base64
import cv2
import requests
import ddddocr
import pytesseract

cookies = {
    'acw_tc': '0b6e704617242999158921224e11f52a14b9ad6e775ce3f3ae0194b8061b3c',
    'ssxmod_itna': 'WqGh0KGKiKYKYv50LWT9DyjbGOQA5jheE+dD/8KmDnqD=GFDK40ooBeDCYmFYF3mquE4CUl0H34MboC2o55tr7fewDU4i8DCwu4ogmDYY8Dt4DTD34DYDixibkxi5GRD0KDFF5XUZ9Dm4GWFqGfDDoDY86RDitD4qDBCodDKqGgFMDsCwDD0Mq4KBhQKe2j7mt3pwqekAhcD0tdxBLxIpGcGmFkoiNeOccDNEQDzw7DtutS9kd3x0PyBMUDMoxAYhvP4MoXWYx40Y4b8YvRuxoP4wqmC6xtQV4oB244DDfeI7zxD',
    'ssxmod_itna2': 'WqGh0KGKiKYKYv50LWT9DyjbGOQA5jheE4G9QHFDBkiq7pIKUHccIpH+SMlZIeyAZM9x1Xzj32rDBYl7bC52CqTu+Ts/w0fPM9r=uaXXAgChr8W1WKOy1gFyA1nxczPzBdvR8uszttOyttOehL7WGLAvGHEHb9=vTSrcb38chQ94WdzPIMcE+/DfrupGdyla=rZuzWxid=A3TCjRLNlRLIOLhUZSbGOMCxNyCC0R0UcSKID07Cx08DYKx4D=',
}

headers = {
    'Accept': 'application/json, text/plain, */*',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    # 'Cookie': 'acw_tc=0b6e704617242999158921224e11f52a14b9ad6e775ce3f3ae0194b8061b3c; ssxmod_itna=WqGh0KGKiKYKYv50LWT9DyjbGOQA5jheE+dD/8KmDnqD=GFDK40ooBeDCYmFYF3mquE4CUl0H34MboC2o55tr7fewDU4i8DCwu4ogmDYY8Dt4DTD34DYDixibkxi5GRD0KDFF5XUZ9Dm4GWFqGfDDoDY86RDitD4qDBCodDKqGgFMDsCwDD0Mq4KBhQKe2j7mt3pwqekAhcD0tdxBLxIpGcGmFkoiNeOccDNEQDzw7DtutS9kd3x0PyBMUDMoxAYhvP4MoXWYx40Y4b8YvRuxoP4wqmC6xtQV4oB244DDfeI7zxD; ssxmod_itna2=WqGh0KGKiKYKYv50LWT9DyjbGOQA5jheE4G9QHFDBkiq7pIKUHccIpH+SMlZIeyAZM9x1Xzj32rDBYl7bC52CqTu+Ts/w0fPM9r=uaXXAgChr8W1WKOy1gFyA1nxczPzBdvR8uszttOyttOehL7WGLAvGHEHb9=vTSrcb38chQ94WdzPIMcE+/DfrupGdyla=rZuzWxid=A3TCjRLNlRLIOLhUZSbGOMCxNyCC0R0UcSKID07Cx08DYKx4D=',
    'Pragma': 'no-cache',
    'Referer': 'https://app.xjnyzg.com/login?redirect=%2Fhome',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0',
    'isToken': 'false',
    'sec-ch-ua': '"Not)A;Brand";v="99", "Microsoft Edge";v="127", "Chromium";v="127"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}

params = {
    'refer__1414': 'n4+xBDgDRAi=D=D7DulDlP6e0=fyQ3Cd4OfrTD',
}

response = requests.get(
    'https://app.xjnyzg.com/api/flow-horse-base/captchaImage',
    params=params,
    cookies=cookies,
    headers=headers,
)

img = response.json()["img"]
with open("captcha.jpg", "wb") as f:
    f.write(base64.b64decode(img))
result = pytesseract.image_to_string(f"captcha.jpg", lang='zh-cn')
print(result)
